<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/7/23
 * Time: 13:47
 */
namespace App\Http\Controllers\Admin\Index;

use App\Http\Controllers\AdminController;
use Illuminate\Support\Facades\DB;

class AdminiController extends AdminController
{
    /**
     * 后台首页...
     * @author  <ZhengYaFeng>
     * @access  <public>
     * @date    <Y-m-d H:i:s>
     * @param   <null>
     * @return  <mixed>
     * @des     <描述:后台首页>
     * @return mixed
     */
    public function index()
    {
        //用户数据
        $data['userNum'] = DB::select('
                select count(id) as userNum from wj_adminuser
                group by status
            ');
        //用户行为数据
        $data['userAcNum'] = DB::select('
                select count(id) as userAcNum from wj_admini_user_log
            ');
        $data['version'] = DB::select('
                    select VERSION() as version
            ');
        //获取当前服务器可用空间
        $servernum = empty(disk_free_space('.')) ? 0 : disk_free_space('.');
        $serverSize =  round(($servernum / (1024 * 1024)), 2);
        $serberTotal = empty(disk_total_space("/")) ? 0 : disk_total_space('.');
        $serberTotalSize = round(($serberTotal / (1024 * 1024)), 2);
        if($serberTotalSize > 1024)
        {
            $serberTotalSize = round(($serberTotalSize / 1024), 2);
            $serverSize = round(($serverSize / 1024), 2);
            $data['serberTotal'] = $serverSize.'/'.$serberTotalSize.'G';
        }else{
            $data['serberTotal'] =  $serverSize.'/'.$serberTotalSize.'M';
        }

        //获取最近用户10次操作情况
        $data['userLog'] = DB::table('admini_user_log')
            ->orderBy('create_time','desc')
            ->paginate(10);

        return view('Admin.Index.index')->withData($data);
    }
}